package com.zlf.sb.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zlf.sb.demo.dto.UserEntityDto;
import com.zlf.sb.demo.entity.UserEntity;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.cursor.Cursor;
import org.apache.ibatis.mapping.ResultSetType;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Scope("prototype")
@Repository
public interface UserMapper extends BaseMapper<UserEntity> {

    /**
     * 批量插入 仅适用于mysql
     *
     * @param entityList 实体列表
     * @return 影响行数
     */
    Integer insertBatchSomeColumn(Collection<UserEntity> entityList);

    /**
     * 统计总数
     *
     * @return
     */
    @Select("SELECT count(*) FROM user")
    Integer countTotal();

    /**
     * 分页游标查询
     *
     * @return
     */
    @Options(resultSetType = ResultSetType.FORWARD_ONLY)
    @Select("SELECT * FROM user ORDER BY create_time DESC LIMIT #{start}, #{pageSize} ")
    Cursor<UserEntity> getCursorPageData(@Param("start") Integer start, @Param("pageSize") Integer pageSize);
    Long pageListV2Count(@Param("dto") UserEntityDto dto);

    List<UserEntity> pageListV2(@Param("start") Long start, @Param("pageSize") Long pageSize, @Param("dto") UserEntityDto dto);
}
